﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using SXICE.AdminAPI.Filters;
using SXICE.Core.Domains;
using SXICE.Core.Models;
using SXICE.Core.Models.Search;
using SXICE.IService;
using System.Collections.Generic;

namespace SXICE.AdminAPI.Controllers
{
    /// <summary>
    /// 权限菜单控制器
    /// </summary>
    [Route("")]
    [Authorize]
    public class MenuController : ControllerBase
    {
        private readonly IMenuService menuService;

        public MenuController(IMenuService menuService)
        {
            this.menuService = menuService;
        }

        /// <summary>
        ///获取所有信息
        /// </summary>
        /// <param name="pageListQuery">查询条件</param>
        /// <returns></returns>
        [HttpPost]
        [Rights("SearchMenu")]
        public ReturnPageListResult<Menu> GetAll([FromBody] PageListQuery<RecordSearchModel> pageListQuery)
        {
            return menuService.Search(pageListQuery);
        }

        /// <summary>
        ///获取所有信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Rights("SearchMenu")]
        public ReturnResult<List<Menu>> GetAlls()
        {
            return menuService.Search();
        }

        /// <summary>
        /// 添加菜单
        /// </summary>
        /// <param name="menu">菜单信息</param>
        /// <returns></returns>
        [HttpPost]
        [Rights("AddMenu")]
        public ReturnResult<bool> AddMenu([FromBody] Menu menu)
        {
            return menuService.AddMenu(menu);
        }

        /// <summary>
        /// 删除菜单
        /// </summary>
        /// <param name="Id">当前删除菜单的Id</param>
        /// <returns></returns>
        [HttpDelete]
        [Rights("DeleteMenu")]
        public ReturnResult<bool> DeleteMenu(int Id)
        {
            return menuService.Delete(Id);
        }
    }
}